package com.livew.framework.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;

public class XTDateUtil extends DateUtils {

	public static String YYYYMMDD = "yyyy-MM-dd";

	public static final String defaultDatePattern = "yyyy-MM-dd HH:mm:ss";
	public static final String datePatternYYYYMMDD = "yyyyMMdd";
	public static final String datePatternYYMMDD = "yyMMdd";
	public static final String datePatternYY_MM_DD = "yyyy-MM-dd";
	public static final String datePatternYYMM = "yyyyMM";
	public static final String datePatternYYYYVMMVDD = "yyyy/MM/dd";
	public static final String datePatternYYYYVMMVDDHHMMSS = "yyyy/MM/dd HH:mm:ss";
	public static final String datePatternMMDDYYYY = "MM/dd/yyyy";
	public static final String datePatternMMMDDYYYYHHMMSS = "MMM d yyyy HH:mm:ss";
	public static final String datePatternMMMDDYYYY = "MMM d yyyy";
	public static final String datePatternYYYY = "yyyy";
	public static final String datePatternyyyyMMddHHmmss = "yyyyMMddHHmmss";
	public static final String datePatternMMdd = "MM-dd";

	public static String dateToString(Date date, String format) {
		String str = null;
		if (date == null) {
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		str = sdf.format(date);
		return str;
	}

	public static Date strToDate(String str, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = null;
		try {
			date = sdf.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 根据小时判断是否为上午、中午、下午
	 * 
	 * @return
	 */
	public static String getDuringDay() {
		Calendar rightNow = Calendar.getInstance();
		int hour = rightNow.get(Calendar.HOUR_OF_DAY);
		if (hour >= 0 && hour < 6) {
			return "凌晨";
		}
		if (hour >= 6 && hour < 9) {
			return "早上";
		}
		if (hour >= 9 && hour < 11) {
			return "上午";
		}
		if (hour >= 11 && hour <= 14) {
			return "中午";
		}
		if (hour >= 14 && hour <= 18) {
			return "下午";
		}
		if (hour > 18 && hour <= 24) {
			return "晚上";
		}
		return "";
	}
}
